package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.FavModel;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_buy)
public class BuyItemView extends RelativeLayout {

    @ViewById(R.id.optionLayout)
    View optionLayout;
    @ViewById(R.id.dataLayout)
    View dataLayout;
    @ViewById
    TextView stock_name;
    @ViewById
    TextView stock_code;
    @ViewById
    TextView close_price;
    @ViewById
    TextView last_price;
    @ViewById
    TextView incr_percent;

    public BuyItemView(Context context) {
        super(context);
    }

    public BuyItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(FavModel model) {
        stock_name.setText(model.stock_name);
        stock_code.setText(model.stock_code);
        close_price.setText(model.close_price);
        last_price.setText(model.last_price);
        incr_percent.setText(model.incr_percent);

        if (model.isProfit()) {
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
        if (model.isStop()) {
            setAllTextColor(getResources().getColor(R.color.text_color_gray));
        }
    }

    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
        stock_code.setTextColor(textColorId);
        close_price.setTextColor(textColorId);
        last_price.setTextColor(textColorId);
        incr_percent.setTextColor(textColorId);
    }

    public void showMoreOption() {
        optionLayout.setVisibility(View.VISIBLE);
    }

    public void disableMoreOption() {
        optionLayout.setVisibility(View.GONE);
//        dataLayout.setBackgroundColor(R.color);
    }


    @Click(R.id.btnBuy)
    void clickBtnBuy() {

    }

    @Click(R.id.btnDelete)
    void clickBtnDelete() {

    }
}
